#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define N 50004
int nxt[N],dp[2][1003];
signed main(){
	freopen("neck.in","r",stdin);
	freopen("neck.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string a,b;cin>>a>>b;int n=a.size(),m=b.size();
	for(int i=2,j=0;i<=m;i++){
		while(j&&(b[j]!=b[i-1]))	j=nxt[j];
		if(b[j]==b[i-1])	j++;
		nxt[i]=j;
	}
	memset(dp,0x3f,sizeof(dp));dp[0][0]=0;
	for(int ti=0;ti<n;ti++){//start 1
		int i=ti&1;
		for(int j=0;j<m;j++)	dp[i^1][j]=1e9;
		for(int j=0;j<m;j++)if(dp[i][j]>=0){
			dp[i^1][j]=min(dp[i^1][j],dp[i][j]+1);
			int p=j;
			while(p&&(b[p]!=a[ti]))	p=nxt[p];
			if(b[p]==a[ti])	p++;
			dp[i^1][p]=min(dp[i^1][p],dp[i][j]);
		}
	}
	int mn=1e9;
	for(int i=0;i<m;i++){
		mn=min(mn,dp[n&1][i]);
	}
	cout<<n-mn;
	return 0;
}
/*
nezhaheaobing
aobing
*/
